package com.bcc.security.common.msg;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.bcc.security.common.constant.ReturnCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description:返回的响应结果包装对象
 * @Author:Kevin
 * @Date:2018/7/28 20:06
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult {

    private String code;
    private String message;
    private Object data;

    public ResponseResult(ReturnCode returnCode) {
        this.code = returnCode.getCode();
        this.message = returnCode.getMessage();
        this.data = "";
    }

    public ResponseResult(ReturnCode returnCode, Object data) {
        if (data == null) {
            throw new IllegalArgumentException( ReturnCode.PARAM_ERROR.getMessage() );
        }
        this.code = returnCode.getCode();
        this.message = returnCode.getMessage();
        this.data = data;
        /*this.data = JSON.toJSONString( data,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullListAsEmpty,
                SerializerFeature.WriteNullBooleanAsFalse,
                SerializerFeature.WriteMapNullValue );*/
    }

}
